/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ems.database;

import ems.lib.Staff;
import java.sql.Connection;


public class SessionDAO {


    private Connection conn = null; // DBConnection.connect()
    private StaffDAO staffDAO = new StaffDAO();

    public SessionDAO() {
         this.conn  = (DBConnection.getConnection() != null) ? DBConnection.getConnection() : DBConnection.connect();
    }

    /**
     * Authorise method to the staff
     * @param username
     * @param password
     * @return Staff object and its details
     */
    public Staff login(String username, char[] password) {
        Staff staff = null;

        if (staffDAO.getStaff(username) == null)
        {
            return staff;
        }

        StringBuffer result = new StringBuffer();
        if (password.length > 0) {
            result.append(password[0]);
            for (int i = 1; i < password.length; i++) {
                result.append("");
                result.append(password[i]);
            }
        }

        if (result.toString().equals(staffDAO.getStaff(username).getPassword())) {
            staff = staffDAO.getStaff(username);
        }
        return staff;
    }


    /**
     * Authorise method to the staff
     * @param username
     * @param password
     * @return Staff object and its details
     */
    public Staff login(String username, String password) {
        Staff staff = null;

        if (staffDAO.getStaff(username) == null)
        {
            return staff;
        }       

        if (password.equals(staffDAO.getStaff(username).getPassword())) {
            staff = staffDAO.getStaff(username);
        }
        return staff;
    }

    /**
     * Log out the current user
     * @param username
     */
    public void logout(String username) {
    }

    
}
